<?php

include '../../authorization_check.php';
include '../../checkPCandVPC.php';
require_once '../../commonutils/util/PageTemplate.php';
require_once '../../commonutils/db/DBConnectionManager.php';

function listPayments($webPage){
	$webPage->addContent("<table align = 'center' border=1 name='listTable'>");
	$webPage->addContent("<tr>");
		$webPage->addContent("<th>Record No</th>");
		$webPage->addContent("<th>ID</th>");
		$webPage->addContent("<th>Last Name</th>");
		$webPage->addContent("<th>First Name</th>");
		$webPage->addContent("<th>Department</th>");
		$webPage->addContent("<th>Semester Status</th>");
		$webPage->addContent("<th>Year</th>");
		$webPage->addContent("<th>Total Payment (YTL)</th>");
		$webPage->addContent("<th>Bank</th>");
		$webPage->addContent("<th>Credit</th>");
	$webPage->addContent("</tr>");
	
		$result = DBConnectionManager::query("select * from Student s, StudentPayment sp, Bank b, Program p, Semester sem 
			where s.studentID=sp.studentID and 
					s.programCode=$_SESSION[programCode] and 
					sp.semesterID=$_SESSION[semesterID] and 
					b.bankID=sp.bankID and p.programCode=s.programCode and sem.semesterID=sp.semesterID");
		$totalPayment = 0;
		$rowIndex = 1;		
		while($row = mysql_fetch_assoc($result)){
			
			
			$webPage->addContent("<tr>");
				$webPage->addContent("<td>$rowIndex</td>");
				$webPage->addContent("<td>$row[studentID]</td>");
				$webPage->addContent("<td>$row[lastName]</td>");
				$webPage->addContent("<td>$row[firstName]</td>");
				$webPage->addContent("<td>$row[shortName]</td>");
				
				if($row[semesterStatus] == 1){
					$webPage->addContent("<td>Registered</td>");	
				}else{
					$webPage->addContent("<td>Not Registered</td>");
				}
				
				$webPage->addContent("<td>$row[year]</td>");
				
				$payment = $row[amount];
				$totalPayment += $payment;
				$credit = $payment/300;
				$webPage->addContent("<td>$row[amount]</td>");
				$webPage->addContent("<td>$row[name]</td>");
				$webPage->addContent("<td>$credit</td>");
				
			$webPage->addContent("</tr>");
			
			$rowIndex++;
		}
	
	$webPage->addContent("<tr><td colspan = 6/></td><th align=left>TOTAL:</th><th align=left>$totalPayment</th>");
	$webPage->addContent("</tr>");
	$webPage->addContent("</table>");
	
}

include "Top.html";
include 'notifier.php';

$webPage = new Page();

$webPage->addHeader('Student Payment Details');

listPayments($webPage);

$webPage->addFooter(date('Y'), 'IIPIS');

echo $webPage->get();
include 'bottom.php';
?>